package com.controller;

import com.alibaba.dubbo.config.annotation.Reference;
import com.entity.Result;
import com.pojo.OrderSetting;
import com.service.OrderSettingService;

import com.utils.POIUtils;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.multipart.MultipartFile;
import java.io.IOException;
import java.util.List;


@RestController
@RequestMapping("/OrderSetting")
public class OrderSettingController {
    @Reference
    private OrderSettingService orderSettingService;
    @RequestMapping("/Upload")
    public Result upload(MultipartFile excelFile) throws IOException {
        if (excelFile==null){
            return new Result(false,"文件不能为空");
        }
        //校验是否是相关类型
        String filename = excelFile.getOriginalFilename();
        if (!filename.endsWith(".xlsx")){
            return new Result(false,"文件格式错误");
        }
        //读取Excel文件数据,每一行有数组个单元格
        List<String[]> list = POIUtils.readExcel(excelFile);
           Result result= orderSettingService.upload(list);
           return result;
    }
    @RequestMapping("/findByYearAndMonth")
        //查询用户传递的月份,对应的相关数据
    Result findByYearAndMonth(String date){
        Result byYearAndMonth = orderSettingService.findByYearAndMonth(date);
        return byYearAndMonth;
    };
    //设置,单天的数据,原则是存在就修改,不存在就新增
    @RequestMapping("/edit")
    Result edit(@RequestBody OrderSetting orderSetting){
        Result edit = orderSettingService.edit(orderSetting);
        return edit;
    };
}
